def digitToChars(digit):
    if digit == '2':
        return 'abc';
    elif digit == '3':
        return 'def';
    elif digit == '4':
        return 'ghi';
    elif digit == '5':
        return 'jkl';
    elif digit == '6':
        return 'mno';
    elif digit == '7':
        return 'pqrs';
    elif digit == '8':
        return 'tuv';
    elif digit == '9':
        return 'wxyz';
    else:
        return '';

def convert(num):
    """

    Given a digit string, return all possible letter combinations
    that the number could represent.
    A mapping of digit to letters (just like on the telephone buttons) is given.

    Input:Digit string "23"
    Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

    Note:
    Although the above answer is in lexicographical order,
    your answer could be in any order you want. 

    :type num : str
    :rtype list[str]
    """

    wc = len(num);
    if wc == 0:
        print('At least 1 string, please!');
        return None;

    l_chars = [];
    l_cnt = [];
    result_cnt = 1;
    for i in range(0, wc):
        chars = digitToChars(num[i]);
        cnt = len(chars);
        if cnt == 0:
            continue;
        l_chars.append(chars);
        l_cnt.append(cnt);
        result_cnt *= cnt;

    result = [] * result_cnt;
    for j in range(0, result_cnt):
        steps = result_cnt;
        item = [];
        for k in range(0, len(l_chars)):
            steps = steps // l_cnt[k];
            item.append(l_chars[k][(j // steps) % l_cnt[k]]);
        result.append(item);
    return result;
